<template>
  <el-container>
    <el-main>
      <div class="title">{{ row.summary }}</div>
      <el-row class="mt10">
        <span class="info">{{ row.modifyAt | parseTime('{y}-{m}-{d}') }}</span>
        <el-tag class="ml10">{{ row.language }}</el-tag>
        <router-link :to="{name: 'EditCodeSnippet', params: row }">
          <el-button class="ml10" type="text" size="mini" icon="el-icon-edit" plain />
        </router-link>
      </el-row>
      <el-divider />

      <MarkdownViewer :content="row.snippet" />
    </el-main>
  </el-container>
</template>

<script>
import MarkdownViewer from '@/components/MarkdownViewer'
import { fetchCodeSnippet } from '@/api/info/code-snippet'

export default {
  name: 'Snippet',
  components: { MarkdownViewer },
  data() {
    return {
      row: {}
    }
  },
  created() {
    const row = this.$route.params
    this.getCodeSnippet(row.id)
  },
  methods: {
    getCodeSnippet(id) {
      fetchCodeSnippet(id).then(response => {
        this.row = response.result
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-main {
  // height: calc(100vh - 104px);
  padding: 20px !important;

  .title {
    font-weight: bold;
  }
}
</style>
